#include "datamodel.h"

DataModel::DataModel(QObject *parent, int ind) : QAbstractTableModel(parent), m_index(ind)
{
        m_data.push_back(TableRow("Dec", 31));
        m_data.push_back(TableRow("Jan", 31));
        m_data.push_back(TableRow("Feb", 28));
        m_data.push_back(TableRow("Mar", 31));
        m_data.push_back(TableRow("Aprl", 30));
        m_data.push_back(TableRow("Mai", 31));
        m_data.push_back(TableRow("Juny", 30));
        m_data.push_back(TableRow("July", 31));
        m_data.push_back(TableRow("Aug", 31));
        m_data.push_back(TableRow("Sept", 30));
        m_data.push_back(TableRow("Oct", 31));
        m_data.push_back(TableRow("Nov", 30));
}

int DataModel::rowCount(const QModelIndex & ) const
{
   if (m_index == 0)
        return m_data.size();
   else
       return 3;
}

int DataModel::columnCount(const QModelIndex &) const
{
    return 2;
}

QVariant DataModel::data(const QModelIndex &index, int role) const
{   
    if (role == Qt::DisplayRole && index.isValid())
    {        
        if (m_index == 0)
        {
            if(index.column() == 0)
                    return m_data[index.row()].month;
            if(index.column() == 1)
                    return m_data[index.row()].days;
        }
        else
        {
            if(index.column() == 0)
                    return m_data[index.row() + (m_index-3)].month;
            if(index.column() == 1)
                    return m_data[index.row() + (m_index-3)].days;
        }        
    }

    return QVariant();
}
